//
//  VRDeleteAccountView.swift
//  VoiceRoom
//
//  Created by Rae on 2024/3/15.
//

import UIKit

class VRDeleteAccountView: UIView, SAAnimationDelegate, SAAnimationProtocol{

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth - 30.0, height: 300.0)
    }
    
    func animationContainerViewStyle() -> SAAnimationViewStyle {
        .center
    }
    
//    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
//        .dismiss
//    }
    
//    func animation(customAttributes attributes: EKAttributes) -> EKAttributes {
//        var attri = attributes
//        attri.positionConstraints.verticalOffset = .bottomSpace
//        return attri
//    }
    
    
    private lazy var titleLabel         = c_make_ex(UILabel.self)
        .alignment(.center).font(18.font_bold)
        .color(.white).text("Delete account").end()
    
    private lazy var textView       = c_make_ex(UITextView.self)
        .bgColor(.white.alpha(0.06)).corner(20).placeholderFont(14.font_medium)
        .color(.white).placeholderColor(.white.alpha(0.4))
        .placeholder("Can give us feedback where weneed improvement")
        .placeholderInsets(UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)).end()
    
    lazy var doneButton                 = c_make_ex(UIButton.self)
        .font(18.font_bold).color("#FFFC00").text("Done")
        .addTarget(self, selector: #selector(museAction_submit))
        .corner(25).border("#FFFC00", width: 2).end()
    
    lazy var cancelButton                 = c_make_ex(UIButton.self)
        .font(18.font_bold).color(.black).text("Cancel").bgColor("#FFFC00")
        .addTarget(self, selector: #selector(museAction_cancel))
        .corner(25).end()
    
    private lazy var descLabel          = c_make_ex(UILabel.self)
        .line(0).alignment(.center).font(12.font_medium).color("#912F2F")
        .text("All your account information will be deleted please consider carefully !").end()
    
    var deleteClosure: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.fj.bgColor("#1F1E18").corner(20.0)
        
        subviews {
            titleLabel
            textView
            descLabel
            cancelButton
            doneButton
        }
        layout {
            20
            titleLabel
            15
            |-15-textView-15-| ~ 110
            15
            |-26-descLabel-26-|
            15
            |-25-doneButton| ~ 50
        }
        
        titleLabel.centerHorizontally()
        doneButton.width(140)
        cancelButton.width(140).height(50).trailing(25)
        cancelButton.CenterY == doneButton.CenterY
        
        textView.contentInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func museAction_cancel(_ sender: UIButton) {
//        muse.animation(dismiss: self)
        saAnimate.animation(dismiss: self)
    }
    
    @objc private func museAction_submit(_ sender: UIButton) {
        sender.isUserInteractionEnabled = false
        guard let content = textView.text, content.count > 0 else {
            "Please tell us why you want to leave us. ".toast_error
            return
        }
//        RT.deletUserWith { str in
//            AgoraRTMClient.shared._kit?.logout()
//            UserDefaults.standard.setValue(nil, forKey: "CollectList")
//            UserDefaults.standard.setValue(nil, forKey: "Following")
//            UserDefaults.standard.setValue(nil, forKey: "MessageList")
//            UserDefaults.standard.setValue(nil, forKey: "UserInfo")
//            UserDefaults.standard.setValue(nil, forKey: USERINFOKEY)
//            UserDefaults.standard.setValue(nil, forKey: "PayRooms")
//            UserDefaults.standard.removeObject(forKey: "boughtProductID")
//        }
//        textView.resignFirstResponder()
//        self.saAnimate.animation(dismiss: self){
//            // 登录界面
//            UIApplication.window?.rootViewController = LearningNavController(rootViewController: LearningWelcomeViewController())
//        }
    }
}
